package com.hmall.search.web;

import com.hmall.common.dto.ItemDoc;
import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchService service;

    @RequestMapping("/suggestion")
    public List<String> getSuggest(@RequestParam("key") String key) throws IOException {

        return service.getSuggest(key);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams param) throws IOException {
        return service.getFilters(param);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> getList(@RequestBody RequestParams param) throws IOException {
        return service.getList(param);
    }

}
